$(document).ready(function() {
	$('#logon').click(login);
	
	$('#cancle').click(cancle);
	
	$('#submit').click(submit);
});

function login() {
    $('#loginContent').window("open");
	$('#loginContent').window({collapsible:false,
	    minimizable:false,
	    maximizable:false,
	    closable:false,
		closed:false,
		top : '180px',
		tools:[{
	        iconCls:'icon-cancel',
	        handler:function(){
	        	 $('#loginContent').window("close");
	        }
   		 }]
	});
	
	$('#name').focus();
}

function submit() {
	var nameID = $('#name');
	var pwdID = $('#password');
	
	var name = $.trim(nameID.val());
    var pwd = $.trim(pwdID.val());
    
    if ('' == name) {
    	nameID.css('borderColor','red');
    	return false;
    } else {
    	nameID.css('borderColor','');
    }
    
    if ('' == pwd) {
    	pwdID.css('borderColor','red');
    	return false;
    } else {
    	pwdID.css('borderColor','');
    }
    
    var params = {
    	'employee.loginAccount':name,
    	'employee.loginPwd' : pwd
    };
    
    var option = {
   		type: 'POST',
   		url: 'iemployee!loginInFront.action',
   		data: params,
   		success : function(msg){
	      if(msg=='success') {
	      	window.location.href="index.jsp";
	      } else {
	      	$('#errorTip').css('display', '');
	      	pwdID.val('');
	      }
		},
		error : function(XMLHttpRequest, textStatus, errorThrown) {
		     $.messager.alert('确定', '<br/><b>很遗憾，添加出现异常,状态为</b>'  + textStatus + ', 错误为： ' + errorThrown, 'error');
		}
	}
	
	$.ajax(option); 
}

function cancle() {
 	$('#loginContent').window("close");
 	$('#name').val('');
 	$('#password').val('');
}
